import Vue from 'vue'
import Router from 'vue-router'


Vue.use(Router)

const childrenRouter = [
  {
    path : "figure",
    meta: {
      title: '人物'
    },
    component: () => import('../components/views/Figure.vue')
  },
  {
    path : "sect",
    meta: {
      title: '宗派'
    },
    component: () => import('../components/views/Sect.vue')
  },
  {
    path : "figureEdit",
    meta: {
      title: '人物编辑'
    },
    component: () => import('../components/views/FigureEdit.vue')
  }
]

const router = new Router({
  routes: [//一级路由
    {
      path: '/',
      name: 'login',
      meta: {
        title: '登入'
      },
      component: () => import('../components/login.vue')
    },
    {
        path:'/index',
        redirect:"/index/figure",
        meta: {
          title: '首页'
        },
        name:'index',
        component: () => import('../components/index.vue'),
        children: childrenRouter
    }
  ]
})
//路由拦截器，注意不要导致死循环
router.beforeEach((to, from, next) => {
  if (to.matched.length == 0) {
      next('/index');
  } else {
      window.document.title = to.meta.title || admin
      next();
  }
});
// router.beforeEach((to,from,next) =>{
//   Window.document.title = to.meta.title;
//   next()
// })

export default router;